<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <title>意无瑕</title>
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <meta name="keywords" content="fly,layui,前端社区">
    <meta name="description" content="Fly社区是模块化前端UI框架Layui的官网社区，致力于为web开发提供强劲动力">
    <link rel="stylesheet" th:href="@{/static/layui/css/layui.css}">
</head>
<body>

<form class="layui-form" action="">

    <div class="layui-form-item">
        <label class="layui-form-label">用户名</label>
        <div class="layui-input-block">
            <input type="text" name="title"
                   style="width: 80%;"
                   required  lay-verify="required"
                   placeholder="请输入标题"
                   id="user-name"
                   autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">密码</label>
        <div class="layui-input-inline">
            <input type="password" name="password"
                   style="width: 80%;"
                   id="password"
                   required lay-verify="required" placeholder="请输入密码" autocomplete="off" class="layui-input">
        </div>
      <!--  <div class="layui-form-mid layui-word-aux">辅助文字</div>-->
    </div>

    <div class="layui-form-item">
        <div class="layui-input-block">
            <button type="button" id="register-btn" class="layui-btn">提交</button>
        </div>
    </div>

</form>

<script th:src="@{/static/layui/layui.all.js}"></script>
<script>
    ;!function () {
        //无需再执行layui.use()方法加载模块，直接使用即可
        var form = layui.form
            , layer = layui.layer;
        $ = layui.jquery;


        $("#register-btn").on('click', function () {
            var params = {
                userName: $("#user-name").val(),
                passWord: $("#password").val(),
            };
            if (params.userName=='' || params.userName.trim()==''){
                layer.msg('用户名不能为空');
                return;
            }
            if (params.passWord=='' || params.passWord.trim()==''){
                layer.msg('密码不能为空');
                return;
            }

            $.ajax({
                url: '/sys/userRegister',
                method: 'post',
                data: params,
                dataType: 'JSON',
                success: function (response) {
                    if (response.status==0){
                        layer.msg('注册成功',{time:1000},function() {
                            layer.close(layer.index);
                            parent.location.reload();
                        })
                    }else{
                        layer.msg("注册失败:"+response.msg);
                    }
                }
            });
        });
        $("#login-register").on('click',function(){
            layer.open({
                type: 2,
                shade: true,
                title: '用户注册',
                maxmin: false,
                skin: 'layui-layer-rim', //加上边框
                area: ['300px', '400px'], //宽高
                content: '/login/register',
                zIndex: layer.zIndex, //重点1

            });
        });

    }();
</script>
</body>
</html>